package 力扣日常刷题.木22二月.第02天207;

import 力扣日常刷题.ListNode;

/**
 * @author 帅小伙
 * @date 2022/2/7
 * @description
 */
public class Demo20删除链表的节点 {

    public ListNode deleteNode(ListNode head, int val) {
        if(head == null) return head;
        // 删除头节点
        if(head.val == val) return head.next;
        ListNode temp = head;
        while(temp.next.val != val) {
            temp = temp.next;
        }
        temp.next = temp.next.next;
        return head;
    }

}
